Support Emacs HEAD(32)#809
Merged
Merged
Conversation
CC Mode >= 31 (the change for bug#19867) no longer treats a brace block
whose contents are inconclusive -- e.g. a closure body whose first line
is only a comment -- as a statement block. `c-looking-at-statement-block'
now falls back to context analysis, and for an anonymous PHP `function
() {...}' the token before the parameter list is the `function' keyword
rather than a function-name identifier, so the body is misclassified as a
brace list. This mis-indents both the body and its closing brace (the
`lang/function/closure.php' indentation test fails on Emacs 31/32 but
passes on 30.2).
Advise `c-looking-at-statement-block' to report a closure-opening brace
as a statement block. A closure body always is one, so this is also
correct on Emacs versions unaffected by the change.
CC Mode >= 31 fontifies a bare `@' as a keyword because `@new' is registered in `c-type-list-kwds', so the error-control operator in e.g. `@fopen(...)' or `@$a' was highlighted as `php-keyword' rather than `php-errorcontrol-op' (the `lang/errorcontrol.php' faces test fails on Emacs 31/32). The previous matcher `\<\(@\)' never matched: `@' has punctuation syntax, so a word boundary can never precede it. Replace it with a matcher function that highlights a single `@' as the error-control operator, overriding CC Mode's keyword face, while skipping `@' inside strings and comments and the `@new' keyword.
`php-in-string-or-comment-p' calls `syntax-ppss', which may trigger `syntax-propertize' and clobber the match data set by the preceding `re-search-forward'. That could misplace the `@new' look-ahead check and the face applied by font-lock. Wrap the call in `save-match-data' so the matched `@' is preserved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes php-mode work on Emacs HEAD (the future Emacs 32) while keeping Emacs 27 through 30 working.
CI is green on Emacs 27.2, 28.2, 29.4, 30.2, and snapshot across Linux, macOS, and Windows.
CC Mode regressions in Emacs 31 and later
Two defects come from CC Mode changes that landed between Emacs 30.2 and 31.0.90.
Both are masked on older Emacs and only appear from 31 onward.
Closure body indentation
The change for bug#19867 made
c-looking-at-statement-blockstop treating a brace block as a statement block when its content is inconclusive, for example a closure body whose first line is only a comment.CC Mode then falls back to context analysis.
For an anonymous
function () { ... }the token before the parameter list is thefunctionkeyword rather than a function name, so the body is classified as a brace list.That mis-indents both the body and its closing brace.
The
lang/function/closure.phpindentation test fails on Emacs 31 and 32 but passes on 30.2.Fix: advise
c-looking-at-statement-blockto report a closure opening brace as a statement block.A closure body always is one, so the advice is also correct on Emacs versions that are not affected.
Error control operator
@CC Mode 31 fontifies a bare
@as a keyword, because@newis registered inc-type-list-kwds.The error control operator in
@fopen(...)or@$awas highlighted asphp-keywordinstead ofphp-errorcontrol-op.The old matcher
\<\(@\)never matched anything, because@has punctuation syntax and a word boundary can never precede it.The
lang/errorcontrol.phpfaces test fails on Emacs 31 and 32.Fix: replace the matcher with a function that highlights a single
@as the error control operator with override, while skipping@inside strings and comments and the@newkeyword.The match data is guarded with
save-match-data, becausephp-in-string-or-comment-pcallssyntax-ppss, which can runsyntax-propertizeand clobber the match set for font-lock.Other Emacs HEAD compatibility fixes
c-after-brace-list-decl-kwds
CC Mode renamed
c-after-brace-list-decl-kwdstoc-after-enum-list-kwds.Keep the old name defined so the transitional lookup in cc-langs stays quiet.
rx forms
Replace bare
anywithnonlin several rx patterns.Both match any character except newline, and
nonlstates the intent directly.Obsolete font-lock variables
Several
font-lock-*-facevariables are now obsolete.Wrap the assignments in
with-suppressed-warningsto silence byte-compile warnings without changing behavior.